#include "mycamera.h"
#include <QDebug>
#include <opencv.hpp>
#include <QImage>
#include <QThread>

MyCamera::MyCamera(QObject *parent): QObject(parent)
{
    m_isCloseCam=false;
}

void MyCamera::openCam()
{
    cv::VideoCapture capture(0);
    if(!capture.isOpened())
    {
        qDebug()<<"相机打开失败！";
        return;
    }
    cv::Mat imgMat;
    while (!m_isCloseCam)
    {
        if(!capture.read(imgMat))
        {
            qDebug()<<"帧获取失败！";
            return;
        }

        QImage imgQ(imgMat.data,imgMat.cols,imgMat.rows,imgMat.step,QImage::Format_RGB888);
        m_imgQ=imgQ.rgbSwapped();

        emit sigCurrentImgQ(m_imgQ);

        cv::waitKey(30);
    }
}
void MyCamera::closeCam()
{
    m_isCloseCam=true;
}
